/**
 * @author 陈泰来
 * @version V1.0
 * @Project echo-java-base
 * @Title 一大群
 * @Description *
 * @Package designmodel.composite
 * @date 2021/3/3 9:10 上午
 * @Copyright:学如逆水行舟，不进则退 .
 */
package designmodel.composite;

import designmodel.composite.observer.Observable;
import designmodel.composite.observer.Observer;

import java.util.ArrayList;

public class Flock implements Quackable {

    Observable observable;

    public Flock() {
        observable = new Observable(this);
    }

    ArrayList<Quackable> quackers = new ArrayList<>();

    public void add(Quackable quackable) {
        quackers.add(quackable);
    }


    @Override
    public void quack() {
        for (Quackable quackable : quackers) {
            quackable.quack();
        }
    }

    @Override
    public void registerObserver(Observer observer) {
        observable.registerObserver(observer);
    }

    @Override
    public void notifyObservers() {
        observable.notifyObservers();
    }
}
